package com.moss.cloud.base.biz.listener;

import com.moss.cloud.base.biz.event.RegionChangeEvent;
import com.moss.cloud.base.biz.service.ISysProvincesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * 行政区划变更事件处理中心--此类消息必须是事务处理完成之后再调用
 *
 * @author 瑾年
 * @date 2023年12月5日
 */
@Slf4j
@Component
public class RegionListener {
    private final ISysProvincesService sysProvincesService;

    public RegionListener(ISysProvincesService sysProvincesService) {
        this.sysProvincesService = sysProvincesService;
    }
    /**
     * 监听行政区划变更事件
     *
     * @param event
     */
    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
    public void handleRegionChaneEvent(RegionChangeEvent event) {
        log.info("监听行政区划变更事件->变更类型:{}", event.getChangeType());
        sysProvincesService.loadProvinces();
    }

}
